#include "Inc/rlc.h"

void System_init(void){
	Port_Init();
	Uart_Init();
	CCP_Init();
    
    LCD_Init();

}

void Port_Init(void){  	

	P0M1 = 0x00;		
	P0M0 = 0X00;
	P1M1 = 0x00;
	P1M0 = 0x00;
	P2M1 = 0x00;
	P2M0 = 0x00;
	P3M1 = 0x80;
	P3M0 = 0x80;
	P4M1 = 0x00;
	P4M0 = 0x00;
	P5M1 = 0x00;
	P5M0 = 0x00;

	BUTTON_INT0 = 1;
	BUTTON_INT1 = 1;
	IT0 = 1;
	EX0 = 1;
	PX0 = 1;
			
}

void Uart_Init(void){		//115200bps@24.000MHz

	SCON = 0x50;		
	AUXR |= 0x40;		
	AUXR &= 0xFE;		
	TMOD &= 0x0F;		
	TL1 = 0xCC;	
	TH1 = 0xFF;		
	ET1 = 0;		
	TR1 = 1;	
}

void CCP_Init(void){
	
	AUXR1 &= 0xEF;      		//CCP_S0=0 CCP_S1=1
	AUXR1 |= 0x20;          	//(P2.4/ECI_3, P2.5/CCP0_3, P2.6/CCP1_3)
	
	CCON = 0;                       
    CL = 0;                         
    CH = 0;
    CCAP0L = 0;
    CCAP0H = 0;
    CMOD = 0x01;                    //In:SysCLK/12 t=0.5us/Pulse Interrupt Enable
    CCAPM0 = 0x21;                  //up
//  CCAPM0 = 0x11;                  //down
//  CCAPM0 = 0x31;                  //up&down

    CR = 1;                         
		
}


void SendChar(uchar a){
	
	SBUF = a;		
	while(TI == 0);		
	TI=0;			   	
	
}

